package com.cskaoyan.service.admin.impl;

import com.cskaoyan.bean.BasePageInfo;
import com.cskaoyan.bean.MarketAddress;
import com.cskaoyan.bean.MarketAddressExample;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.mapper.MarketAddressMapper;
import com.cskaoyan.service.admin.MarketAddressService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author LC_RSH
 * @date 2022/6/25 22:26
 */
@Service
public class MarketAddressServiceImpl implements MarketAddressService {
    @Autowired
    MarketAddressMapper addressMapper;

    /**
     * 通过名字及id查找地址
     *
     * @return
     * @author LC_R-SH
     * @since 2022/06/28 13:53
     */
    @Override
    public CommonData<MarketAddress> query(String name, Integer userId, BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketAddressExample marketAddressExample = new MarketAddressExample();
        MarketAddressExample.Criteria criteria = marketAddressExample.createCriteria();
        if (!StringUtils.isEmpty(name)) {
            name = "%" + name.trim() + "%";
            criteria.andNameLike(name);
        }
        if (userId != 0) {
            criteria.andUserIdEqualTo(userId);
        }
        criteria.andDeletedEqualTo(false);
        List<MarketAddress> addressList = addressMapper.selectByExample(marketAddressExample);
        PageInfo<MarketAddress> pageInfo = new PageInfo<>(addressList);
        return CommonData.data(pageInfo);
    }
}

/**
 * address
 *
 * @author 86157
 * @since 2022/06/25 22:26
 */